package gps.implementationAPI;

import gps.GPSRun;
import gps.api.GPSProblem;
import gps.api.GPSRule;
import gps.api.GPSState;
import gps.rules.Rules;

import java.awt.Point;
import java.util.LinkedList;
import java.util.List;

public abstract class GPSGenericProblemImplementation implements GPSProblem {

	protected GPSState gpsState;
	protected Rules gpsRules;
	protected List<GPSState> goalStates;
	
	public GPSGenericProblemImplementation() {
		this.gpsState = new GPSStateImplementation();
		this.gpsRules = new Rules();
		this.goalStates = new LinkedList<GPSState>();
	}
	
	public GPSState getInitState() {
		return this.gpsState;
	}

	public List<GPSState> getGoalsState() {
		if (this.goalStates.isEmpty()) {
			for (int i = 0; i < GPSRun.N; i++) {
				for (int j = 0; j < GPSRun.N; j++) {
					goalStates.add(GPSStateImplementation.getOneGoalState(new Point(i, j)));
				}
			}
		}
		return goalStates;
	}

	public List<GPSRule> getRules() {
		if (this.gpsRules.getRules().isEmpty()) {
			this.gpsRules.createRules();
		}
		return this.gpsRules.getRules();
	}

}
